package com.example.cc.server.service;

import com.example.cc.common.dto.RegisterDTO;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 客户端注册管理，使用内存模型简化
 */
@Service
public class ClientRegisterMemoryService {

    private final Map<String, RegisterDTO> registeredClientMap = new ConcurrentHashMap<>();

    // 注册客户端
    public void register(RegisterDTO registration) {
        registeredClientMap.putIfAbsent(registration.getClientId(), registration);
    }

    // 注销客户端
    public void unregister(String clientId) {
        registeredClientMap.remove(clientId);
    }

    // 查询所有注册的客户端
    public Map<String, RegisterDTO> findAll() {
        return registeredClientMap;
    }

    // 根据客户端ID查询
    public RegisterDTO findByClientId(String clientId) {
        return registeredClientMap.get(clientId);
    }
}
